package com.example.server.controller;

import com.example.server.entity.Product;
import com.example.server.service.ProductService;
import com.example.server.util.Util;
import org.apache.catalina.LifecycleState;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.awt.event.PaintEvent;
import java.util.List;

@Controller
@RequestMapping("product")
public class ProductController extends BaseController{

    private final ProductService productService;

    public ProductController(ProductService productService) {
        this.productService = productService;
    }

    @PostMapping("create")
    @ResponseBody
    private boolean create(@RequestPart MultipartFile file,@RequestPart MultipartFile[] files,@RequestBody Product product){
        String path = "D:/softwear/shixun/project-team06/server/src/main/resources/static/picture/product";
        product.setPicture(Util.savePicture(file,path));
        product.setPictures(Util.savePicture(files,path));
        productService.create(product);

        return true;
    }

    @GetMapping("queryAllCommented")
    @ResponseBody
    private List<Product> queryAllCommented(){
        return productService.queryList("queryAllCommented",null);
    }

    @GetMapping("queryAll")
    @ResponseBody
    private List<Product> queryAll(){
        return productService.queryAll();
    }
}